/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Business;

import DAO.Bill_DAO;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author anhvtn_b00545
 */
public class BillProcess_BS {

    Connection conn= null;
    Bill_DAO o= new Bill_DAO();
    loadBill load;
    loadBillDetails loadorder;
    List<Bill_BS> lstOr;
     private BillProcess_BS() {
    }

    public BillProcess_BS(List<Bill_BS> bill) {
        this.lstOr = bill;
    }
    public loadBill viewOrder() {
        load = new loadBill(o.loadOrderList());
        return load;
    }

    public loadBillDetails viewOrderDetails(int bID) throws SQLException{
        loadorder = new loadBillDetails(o.loadOrderDetails(bID));
        return loadorder;
    }
    public int addOrder(Bill_BS B)
    {
        int newId = o.addOrder(B);
        if(newId != -1)
        {
            return newId;
        }
        else
        {
            JOptionPane.showMessageDialog(null,"Order doesn't create successfull!", "Eror", JOptionPane.ERROR_MESSAGE);
            return -1;
        }
    }
     public boolean addOrderDetails(BillDetails_BS BD)
    {
        boolean success = false;
        if(o.addOrderDetails(BD) == true)
        {
             lstOr = o.loadOrderList();
             load.addOrder(lstOr);
             success = true;
        }
        return success;
    }

     private static BillProcess_BS op;
    public static BillProcess_BS getOrder() {
        if(op == null) {
            op = new BillProcess_BS();
        }
        return op;
    }


}
